package com.ln.property_control.controller;

import com.ln.property_control.pojo.BorrowVo;
import com.ln.property_control.pojo.Department;
import com.ln.property_control.pojo.PropertyVo;
import com.ln.property_control.service.BorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("borrow")
public class BorrowController {

    @Autowired
    private BorrowService borrowService;

    //资产报状态修显示
    @RequestMapping("/index")
    @ResponseBody
    public Map<String,Object> scrapFindAll(Integer page, Integer limit){
        Map<String, Object> map = borrowService.getBorrowVo(page, limit);
        return map;
    }

    //资产报状态修显示
    @RequestMapping("/getReturn")
    @ResponseBody
    public Map<String,Object> getReturn(Integer page, Integer limit){
        Map<String, Object> map = borrowService.getReturn(page, limit);
        return map;
    }

    //资产报状态修显示
    @RequestMapping("/getHistory")
    @ResponseBody
    public Map<String,Object> getHistory(Integer page, Integer limit){
        Map<String, Object> map = borrowService.getHistory(page, limit);
        return map;
    }



    //资产报状态修显示
    @RequestMapping("/findDetail")
    @ResponseBody
    public ModelAndView findDetail(String id){
        System.out.println(id);
        ModelAndView mv = new ModelAndView();
        BorrowVo findBorrowVo = borrowService.getFindBorrowVo(id);
        List<BorrowVo> borrowName = borrowService.getBorrowName(id);
        System.out.println(borrowName);
        mv.addObject("bN",borrowName);
        mv.addObject("fbo",findBorrowVo);
        mv.setViewName("asset/borrow/detail");
        return mv;
    }

    //部门查询
    @RequestMapping("/getDepaId")
    @ResponseBody
    public List<Department> getDepaId(int id){
        List<Department> depaId = borrowService.getDepaId(id);
        return depaId;
    }

    //借用申请
    @RequestMapping("/getAddBorrow")
    @ResponseBody
    public int getAddBorrow(BorrowVo borrowVo,String[] property_id){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        borrowVo.setAdd_time(sdf.format(new Date()));
        int addBorrow = borrowService.getAddBorrow(borrowVo,property_id);
        return addBorrow;
    }

    //审批通过拒绝
    @RequestMapping("/getIsPsaa")
    @ResponseBody
    public int getIsPsaa(BorrowVo borrowVo,HttpSession session){
        int updaSta = borrowService.getUpdaSta(borrowVo,session);
        return updaSta;
    }

    //资产查看
    @RequestMapping("/getProperty")
    @ResponseBody
    public List<PropertyVo> getProperty(String property_dep_id){
        List<PropertyVo> property = borrowService.getProperty(property_dep_id);
        return property;
    }


}
